﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BE;
using DAL;
using System.IO;

namespace BLL
{
    public class RoomWorker
    {
        private RoomDA dbInstance;

        public RoomWorker()
        {
            dbInstance = new RoomDA();
        }

        public int Add(Room room, string username)
        {
            LogWorker lW = new LogWorker();
            Log log = new Log();

            log.Time = DateTime.Now;
            log.User = username;
            log.Type = EventTypes.Add;
            log.Event = "A room with following information has been added - Name: " + room.Name + ", Location ID: " + room.LocationID;

            lW.Add(log);

            return dbInstance.AddRoom(room);
        }

        public Room GetRoom(int id)
        {
            return dbInstance.GetRoom(id);
        }

        public List<Room> GetAllRooms()
        {
            return dbInstance.GetAllRooms();
        }

        public int Edit(Room room, string username)
        {
            LogWorker lW = new LogWorker();
            Log log = new Log();

            log.Time = DateTime.Now;
            log.User = username;
            log.Type = EventTypes.Edit;
            log.Event = "Room with ID = " + room.ID + " has been updated to following - Name: " + room.Name + ", Location ID: " + room.LocationID;

            lW.Add(log);

            return dbInstance.EditRoom(room);
        }

        public int Delete(Room room, string username)
        {
            LogWorker lW = new LogWorker();
            Log log = new Log();

            log.Time = DateTime.Now;
            log.User = username;
            log.Type = EventTypes.Delete;
            log.Event = "Room with ID = " + room.ID + " and Name: " + room.Name + " has been deleted";

            lW.Add(log);

            return dbInstance.DeleteRoom(room.ID);
        }

        public List<Room> GetLocationlessRooms()
        {
            return dbInstance.GetLocationLessRooms();
        }

		public List<Room> GetRoomsByLocation(int locationId)
		{
			return dbInstance.GetRoomsByLocation( locationId );
		}
    }
}
